#include "FiveWin.ch"

//----------------------------------------------------------------------------//

CLASS TButton FROM TControl

   DATA   bAction

   METHOD New( nRow, nCol, cCaption, oWnd, bAction, nWidth, nHeight,;
               nHelpId, oFont ) CONSTRUCTOR
   METHOD ReDefine( nId, bAction, oWnd, nHelpId ) CONSTRUCTOR
   METHOD Click()
   METHOD cToChar() BLOCK { | Self | Super:cToChar( "BUTTON" ) }

ENDCLASS

//----------------------------------------------------------------------------//

METHOD New( nRow, nCol, cCaption, oWnd, bAction, nWidth, nHeight, ;
            nHelpId, oFont ) CLASS TButton

   DEFAULT cCaption := "&Button",;
           oFont    := TFont():New( "System", 7, 10 ),;
           nWidth   := ( Len( cCaption ) + 2 ) * oFont:nWidth,;
           nHeight  := oFont:nHeight + Int( oFont:nHeight / 4 ),;
           nHelpId  := 100

   ::cCaption = cCaption
   ::nTop     = nRow * ( oFont:nHeight + Int( oFont:nHeight / 4 ) )
   ::nLeft    = nCol * oFont:nWidth
   ::nBottom  = ::nTop  + nHeight
   ::nRight   = ::nLeft + nWidth
   ::nHelpId  = nHelpId
   ::bAction  = bAction
   ::oWnd     = oWnd
   ::oFont    = oFont
   ::nStyle   = nOR( WS_CHILD, WS_VISIBLE, WS_TABSTOP )
   ::nId      = ::GetNewId()

   if oWnd:ClassName() != "TDIALOG"
      ::Create( "BUTTON" )
   else
      oWnd:DefControl( Self )
   endif

return

//----------------------------------------------------------------------------//

METHOD ReDefine( nId, bAction, oWnd, nHelpId ) CLASS TButton

   ::nId     = nId
   ::bAction = bAction
   ::hWnd    = 0
   ::nHelpId = nHelpId
   ::oWnd    = oWnd

   oWnd:DefControl( Self )

return

//----------------------------------------------------------------------------//

METHOD Click() CLASS TButton

   if ::bAction != nil
      Eval( ::bAction )
   endif

return

//----------------------------------------------------------------------------//
